﻿using H;
using H.Kernel;
using H.Kernel.Login;
using H.Logs;
using HModel;
using System;
using System.Threading;

namespace HAuto
{
    internal class App : IApp
    {
        public static void Main(string[] args)
        {
            ControllerContext controllerContext = new ControllerContext();
            controllerContext.Log = HService.DefaultLoggerFactory.Value.GetInstance();
            controllerContext.Log.AddListener(HService.DefaultLoggerFactory.Value.CreateLocalLogListener());
            controllerContext.Log.AddListener(HService.DefaultLoggerFactory.Value.CreateWebLogListener("192.168.2.36", 5566, "HAuto"));
            ILog Log = controllerContext.Log.GetInstance("HAuto");
            Log.Debug("正在加载图像识别插件");
            controllerContext.Eye = HService.DefaultRemotingFactory.Value.GetEyeFactory("127.0.0.1", 7754)?.CreateInstance("H.DML")
                                    ?? throw new Exception("初始化DML失败");
            Log.Debug("正在加载键鼠操作插件");
            controllerContext.Hand = HService.DefaultRemotingFactory.Value.GetHandFactory("127.0.0.1", 7754)?.CreateInstance("H.KML")
                                     ?? throw new Exception("初始化KML失败");
            Log.Debug("正在加载主数据");
            controllerContext.Dao = HService.DefaultDaoFactory.Value.CreateInstance(HService.GetEnvPath("main.hdb"), null, false);
            controllerContext.Dao.UpdateTable<GameRegionEntity>();

            ILogin loginController = new ClientLogin(controllerContext)
            {
                StarterPath = @"E:\地下城与勇士\TCLS\Client.exe",
                //StarterPath = @"D:\game\WeGameApps\地下城与勇士\TCLS\Client.exe",
                Region = "江苏8区",
                UserName = "379292814",
                Password = "aaaa1100"
            };
            bool ret = loginController.Login(CancellationToken.None);
            Log.Debug("程序运行结果:" + ret);
        }
    }
}
